<template>
  <div id="AsnDetail">
    <v-tableTitle :btnConfig="btnConfig"
                  @backList='backList'
                  @save='save'
                  @newZj='newZj'
                  @cfpjh='cfpjh'></v-tableTitle>
    <div class="detail">
      <v-navMenu :detailNav="detailNav"
                 :menuData="menuData"
                 @setMentActive="setMentActive"
                 v-if='navMenuDis'></v-navMenu>
      <component :inputData="{detailData,selectData}"
                 :is="currentComponent"
                 ref="comRef"></component>
    </div>

  </div>

</template>

<script>
import detail from "commons/Detail";
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import tableTitle from "@/components/commons/TableTitle";

export default {
  name: "Detail",
  mixins: [baseMixin, config],
  data () {
    return {
      navMenuDis: true,
      flag: true,
      newFlag: false,
      selectData: {},
      detailData: {},
      detailNav: "1",
      type: '',
      componentConfig: [
        {
          name: "asnDetails",
          label: this.$t('in.rtxstuff'),
          component: () => import('./page/AsnDetails.vue')
        },
        {
          name: "rtxqcxq",
          label: this.$t('in.rtxstuffDetail'),
          component: () => import('./page/rtxqcxq.vue')
        },
        {
          name: "inspectPro",
          label: this.$t('in.inspectPro'),
          component: () => import('./page/inspectPro.vue')
        },
        {
          name: "inspectProxxqy",
          label: this.$t('in.inspectProXq'),
          component: () => import('./page/inspectProxxqy.vue')
        },
        {
          name: "inspectReporty",
          label: this.$t('in.inspectReporty'),
          component: () => import('./page/inspectReproty.vue')
        },
        {
          name: "inspectReprotyXq",
          label: this.$t('in.inspectReprotyXq'),
          component: () => import('./page/inspectReprotyXq.vue')
        },
      ],
      deletetrans: true,
    }
  },
  computed: {
    btnConfig () {
      if (this.detailNav == 1) {
        return [
          { label: this.$t('in.autoFill'), certigier: !this.btnPermNameList.includes('WM010704'),  invalid: "save" },
          { label: this.$t('in.splitQc'), certigier: this.deletetrans||!this.btnPermNameList.includes('WM010705'), invalid: "cfpjh" },
        ]
      } else if (this.detailNav == 2 || this.detailNav == 4 || this.detailNav == 6) {
        return [
          { label: this.$t('common.return'), certigier: !this.btnPermNameList.includes('WM010707'),  invalid: "backList" },
        ]

      } else if (this.detailNav == 5) {
        return [
          { label: this.$t('common.create'), certigier: !this.btnPermNameList.includes('WM010706'),  invalid: "newZj" },
        ]
      }
      return []
    },
    currentComponent () {
      return this.componentConfig[this.detailNav - 1].component;
    }
  },
  methods: {
    newZj () {
      this.navMenuDis = false
      this.type = '3'
      this.detailNav = "6";
      this.detailData = {
        excipientsnum: '',
        materialgrade: '',
        badratio: '',
        allowratio: '',
        materialquantity: '',
        rtxdl: '',
      }

    },
    cfpjh () {
      this.$refs.comRef.inintDialog()
    },
    async change (flag) {
      this.deletetrans = flag
    },
    save () {
      let data = { 'rtxchecklist': this.selectData.rtxchecklist };
      this.$api.post('/updateRtxQcDetailAll', data).then(res => {
        
          this.$message.success(res.returnMgr)
      })
    },
    //进入详情
    async setdialog (data, type) {
      this.type = type
      if (type === '1') {
        try {
          let res = await this.$api.get(`/queryRtxQcDetailByCode/` + data.rtxchecklist + '/' + data.serialkey);
          
            this.detailData = res.bean;
            this.detailNav = "2";
        } catch (e) {
          this.$message.error(e);
        }
      } else if (type === '2') {
        try {
          let res = await this.$api.get(`/queryRtxQcTypeByCode/` + data.rtxchecklist + '/' + data.serialkey);
          
            this.detailData = res.bean;
            this.detailNav = "4";
        } catch (e) {
          this.$message.error(e);
        }
      } else {
        try {
          let res = await this.$api.get(`/queryRtxQcReportByCode/` + data.rtxchecklist + '/' + data.serialkey);
          
            this.detailData = res.bean;
            this.detailNav = "6";
        } catch (e) {
          this.$message.error(e);
        }
      }
      this.navMenuDis = false

    },
    //返回试图
    backList () {
      this.navMenuDis = true
      if (this.type === '1') {
        this.detailNav = "1";
      } else if (this.type === '2') {
        this.detailNav = "3";
      } else {
        this.detailNav = "5";
      }

    },
    setMentActive (key) {
      this.detailNav = key;
    },
    async getData () {
      try {
        let res = await this.$api.get(`/queryRtxQcByCode/` + this.selectData.whseid + '/' + this.selectData.rtxchecklist);
        
          this.$nextTick(() => {
            this.detailData = {
              ...this.detailData,
              ...res.bean
            };
          });
      } catch (e) {
        this.$message.error(e);
      }
    },
  },
  mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.detailData = data.detail;
      this.selectData = data.routeData;
      this.detailNav = data.detailNav;
    } else {
      this.selectData = this.$store.state.routeData;
      this.getData();
    }
  },
  components: {
    "v-detail": detail,
    "v-navMenu": navMenu,
    "v-tableTitle": tableTitle,
  },

}
</script>

<style scoped>
</style>
